補充已下列解決問題
http://ithelp.ithome.com.tw/question/10002871
透過 WMI Script 找出 now 與 lastbootuptime 相比較 得知 電腦這次已經開機多久時間
下列程式存成 *.vbs檔 直接執行即可 得出下列結果
Boot Time: 2008/5/29 上午 08:54:14
System Uptime = 0 Day(s) 3 Hour(s) 59 Mins(s)
strComputer = "."
Set dtmInstallDate = CreateObject( _
"WbemScripting.SWbemDateTime")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
strTemp=objOperatingSystem.lastbootuptime
'wscript.echo objOperatingSystem.lastbootuptime
wscript.echo "Boot Time: " & getmydat (objOperatingSystem.lastbootuptime)
Next
' Get the last boot date/time
'strTemp = objItem.LastBootUpTime
dtBoot = CDate(Mid(strTemp, 5, 2) & "/ " & Mid(strTemp, 7, 2) & "/" & _
Mid(strTemp, 1, 4) & " " & Mid(strTemp, 9, 2) & ":" & _
Mid(strTemp, 11, 2) & ":" & Mid(strTemp, 13, 2))
' Adjust boot date/time for current time zone
dtBoot = DateAdd("h", 0, dtBoot)
' Determine uptime
intMins = DateDiff("n", dtBoot, Now)
intDays = intMins \ 1440
intMins = intMins Mod 1440
intHours = intMins \ 60
intMins = intMins Mod 60
WScript.Echo "System Uptime = " & _
intDays & " Day(s) " & _
intHours & " Hour(s) " & _
intMins & " Mins(s) "
Function getmydat(wmitime)
dtmInstallDate.Value = wmitime
getmydat = dtmInstallDate.GetVarDate
End function
thanks for sharing...
想請問: 這個問題是為省電著想??
主要是配合之前的分享
http://ithelp.ithome.com.tw/question/10002861
能查出到底誰下班不關機順便也能列出開機多久時間了
若發現開機時間超過1天表示下班未關機
可順便發個訊息到Client桌面
以下為程式碼: chr(20)為換行指令 代表 ^T
Set objShell = CreateObject("WScript.Shell")
strMessage1=" 這台電腦下班未關機 ; 請配合節約能源措施關機 "
strMessage2=" "
strCommand = "net send " & strComputer & strMessage1 &chr(20)&chr(20)& strMessage2
Set objExecObject = objShell.Exec(strCommand))
這個好像不錯用,不過應該可以用來對付小鬼的電腦吧 xd
我存檔好了
點開執行後 跳出警告視窗 寫錯誤
錯誤:必須提供陳述式
這是哪裡問題呀?
vista不能這樣用嗎?
不過我有重開機過耶~還寫17小時
原來重開機 不算關機喔